package com.zhi.mbtibot.controller;


import com.zhi.mbtibot.common.Result;
import com.zhi.mbtibot.entity.Message;
import com.zhi.mbtibot.service.MessageService;
import com.zhi.mbtibot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能:
 * 作者:YukiSu
 * 日期:2024/7/16 23:21
 */
@RestController
@RequestMapping("/message")

public class MessageController {
    @Autowired
    UserService userService;
    @Autowired
    MessageService messageService;
    @GetMapping("/{uid}")
    public Result getMessageListByUid(@PathVariable Integer uid) {
        if (userService.getUserById(uid) == null) {
            return Result.error("用户不存在");
        }
        return Result.success(messageService.getMessageListByUid(uid));
    }
    @PostMapping("/{uid}")
    public Result sendMessageByUid(@PathVariable Integer uid, @RequestBody Message message) {
        if (userService.getUserById(uid) == null) {
            return Result.error(("用户不存在"));
        }
        message.setUid(uid);
        messageService.addMessage(message);
        return Result.success("添加信息成功");
    }

}